// 有限curry/无限curry

function curry(fn){
    var curryFn = (...args) => {
        if(args.length === fn.length){
           return fn(...args)
        } else {
            return (...params) => {
                return curryFn(...[...args, ...params])
            }
        }
    }
    return curryFn
}

const a = (a, b, c, d) => a + b + c + d
const fn = curry(a)
console.log(fn(1, 2)(2, 4))


function currySum(...args){
    let params = [...args]
    function curryFn(...p){
        params = params.concat(p)
        return curryFn
    }
    curryFn.toString = () => params.reduce((pre, next) => pre + next, 0)
    return curryFn
}
console.log(currySum(1, 2, 3, 4)(5)(6, 7).toString())


function debounce(fn, time){
    let timer = null
    return (...args) => {
        if(timer) clearTimeout(timer)
        timer = setTimeout(() => {
            fn.call(this, ...args)
        }, time);
    }
}

function throttle(fn, time){
    let timer = null
    return (...args) => {
        if(timer) return
        timer = setTimeout(() => {
            fn.call(this, ...args)
        }, time);
    }
}